package com.spps;

public class StringUtils {
    public static String capitalizes(String str) {
        if (str.isEmpty()) {
            return "";
        }
        return str.substring(0, 1).toUpperCase() + str.substring(1);
    }

    // public static String toUnderscoreCase(String str) {
    // strtolower(preg_replace("/([A-Z]+)/", "_$1", $data));
    // str.replaceAll("([A-Z])+", str)
    // return "";
    // }

    public static String toLowerCamelCase(String str) {
        String[] segments = str.split("_");
        if (segments.length <= 1) {
            return str;
        }
        for (int i = 1; i < segments.length; i++) {
            segments[i] = StringUtils.capitalizes(segments[i].toLowerCase());
        }
        return String.join("", segments);
    }
}
